package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no11_20.no14;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.longestCommonPrefix(new String[]{"abc","aec"}));

    }

    public String longestCommonPrefix(String[] strs) {
        StringBuilder stringBuilder = new StringBuilder();
        int index = 0;
        while(true) {
            if(strs[0].length() <= index){
                break;
            }
            char ch = strs[0].charAt(index);
            int i = 1;
            for (; i < strs.length; i++) {
                if(strs[i].length() <= index || strs[i].charAt(index) != ch){
                    break;
                }
            }
            if(i != strs.length){
                break;
            }
            stringBuilder.append(ch);
            index ++;
        }
        return  stringBuilder.toString();
    }
}
